﻿<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="Equipment.DataAccess" %>
<div id="statusDialog" title="Change Status" class="hidden">
    <table>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
        </tr>
        <tr>
            <th width="100px">
                Status:
            </th>
            <td>
                <div id="dialogStatusContent">
                    <table>
                        <% For Each item As AssetStatus In ViewData("Statuses")%>
                        <tr>
                            <td width="20px">
                                <input id="cbxStatus_<%: item.ID%>" type="radio" name="cbxStatus" value="<%: item.ID%>" />
                            </td>
                            <td id="statusDescLookup_<%: item.ID%>">
                                <%: item.Description%>
                            </td>
                        </tr>
                        <% Next%>
                    </table>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <br />
                <div class="right">
                    <input type="submit" class="button" value="Save" onclick="saveStatus();" />
                    <input type="submit" class="button" value="Cancel" onclick="closeDialog();" />
                </div>
            </td>
        </tr>
    </table>
</div>
<script language="javascript" type="text/javascript">
    var statusDialog = {
        AssetID:0,
        show: function (id) { changeStatus(id); },
        close: function () { closeDialog(); },
        OnSuccess: null
    }

    function closeDialog() {
        $("#statusDialog").dialog("close");
    }

    function changeStatus(id) {
        statusDialog.AssetID = id;
        $("#statusDialog").dialog({
            modal: true,
            width: 400,
            height: 300,
            zIndex: 100
        });
        $("#cbxStatus_" + id).click();
    }

    function saveStatus() {
        var statusID = $('input:radio[name=cbxStatus]:checked').val();
        var statusDesc = $("#statusDescLookup_" + statusID).text();

        jQuery.ajax({
            type: 'POST',
            data: { assetID: statusDialog.AssetID, statusID: statusID },
            url: '<%= Html.AttributeEncode(Url.Action("ShangeAssetStatus")) %>',
            dataType: "json",
            success: function (result) {
                if (result.Result === "ok") {
                    if (statusDialog.OnSuccess != null)
                        statusDialog.OnSuccess(statusDialog.AssetID, statusDesc);
                    closeDialog();
                }
            }
        });
    }

</script>
